<div class="art-post">
	<div class="art-post-tl"></div>
	<div class="art-post-tr"></div>
	<div class="art-post-bl"></div>
	<div class="art-post-br"></div>
	<div class="art-post-tc"></div>
	<div class="art-post-bc"></div>
	<div class="art-post-cl"></div>
	<div class="art-post-cr"></div>
	<div class="art-post-cc"></div>
	<div class="art-post-body">
	<div class="art-post-inner art-article">  
                    <h2 class="art-postheader">[<?php echo ($action == 'edit')?"Sửa danh mục":"Tạo danh mục mới"; ?>]</h2>

                    <span id="message" style="color:red;font-weight:bold;background-color:#f0f8ff;">
        <?php
         if(isset($error))
         {
            foreach($error as $err)
            {
                echo "* $err <br />";
            }
         }

        if(isset($message))
        {
            echo "* $message <br />";
        }
        echo "<br/>";
        ?>
    </span>
    <form name="fr" id="fr" action="<?php echo Utility::getSiteUrl();?>/category/add" method="post">
        <input type="hidden"  name="faction" id="faction" value="<?php  echo $action;?>"/>
    <table class="tbl-form">
        <tr>
            <td>Tên danh mục</td>
            <td><input type="text" name="name" class="form-input" value="<?php if($action == 'edit') if(isset($input)) echo $input->name;?>"/></td>
        </tr>
        <tr>
            <td>Mã</td>
            <td><input type="text" name="code" class="form-input"
                       value="<?php if($action == 'edit') if(isset($input)) echo $input->code;?>"/></td>
        </tr>
        <tr>
            <td>Đường dẫn</td>
            <td><input type="text" name="link" class="form-input" value="<?php if($action == 'edit') if(isset($input)) echo $input->link;?>"/></td>
        </tr>
        <tr>
            <td>Danh mục cha</td>
            <td>
                <select name="parent_id" class="styledselect_form_1">
                    <option value="0">Chọn danh mục</option>
                    <?php
                    if(isset($cat_list))
                    {
                        if($action == 'edit')
                        {
                            foreach($cat_list as $cat)
                            {
                                if(isset($id) && $id == $cat->id) continue;
                                echo "<option value='$cat->id'";
                                if(isset($input) && $input->parent_id == $cat->id) echo "selected='selected'";
                                echo ">";
                                for($i = 0; $i < $cat->c_level; $i++) echo "--";
                                echo " $cat->name</option>";
                            }
                        }
                        else
                        {
                            foreach($cat_list as $cat)
                            {
                            if(isset($id) && $id == $cat->id) continue;
                            echo "<option value='$cat->id'";
                            if(isset($input) && $input['parent_id'] == $cat->id) echo "selected='selected'";
                            echo ">";
                            for($i = 0; $i < $cat->c_level; $i++) echo "--";
                            echo " $cat->name</option>";
                            }
                        }

                    }
                    ?>
                    
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="submit"  value="<?php if($action =='add') echo "Thêm"; else echo "Sửa";?>" />
                <input type="reset" value="Nhập lại" />
                <input type="button" value="Về trang chính" onclick="window.location='<?php echo Utility::getSiteUrl() . '/category/';?>'"/>
            </td>
        </tr>
    </table>
    </form>


                </div>
               </div>
  
		<div class="cleared"></div>
	  </div>
  </div>